import java.util.*;

public class Test2 {
    /**
     * 深搜
     */
    private static int[] x = {-1, 0, 0, 1};
    private static int[] y = {0, -1, 1, 0};
    private static boolean[][] vis;
    private static int path;
    private static int minStep = 0x3f3f3f3f;
    private static int ret = 0;
    private static Map<Integer, Set<Integer>> map = new HashMap<>();
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int m = in.nextInt();
            in.nextLine();
            char[][] board = new char[n][m];
            vis = new boolean[n][m];
            map = new HashMap<>();
            int startX = -1;
            int startY = -1;
            for (int i = 0; i < n; i++) {
                char[] line = in.nextLine().toCharArray();
                for (int j = 0; j < m; j++) {
                    board[i][j] = line[j];
                    if (board[i][j] == 'k') {
                        startX = i;
                        startY = j;
                    }
                }
            }
            if (board[startX][startY] == 'e') {
                minStep = 0;
            }
            vis[startX][startY] = true;
            dfs(board, startX, startY);
            System.out.println(ret == -1 ? -1 : ret + " " + minStep);
        }
    }

    private static void dfs(char[][] board, int row, int col) {
        if (board[row][col] == 'e') {
            minStep = Math.min(minStep, path);
            // 判断这个入口是否已经走过了
            Set<Integer> set = map.get(row);
            if (set == null) {
                set = new HashSet<>();
                map.put(row, set);
                ret++;
            } else {
                if (!set.contains(col)) {
                    ret++;
                }
            }
            set.add(col);
            // 到达出口一定会离开迷宫
            return;
        }
        for (int i = 0; i < 4; i++) {
            int newRow = row + x[i];
            int newCol = col + y[i];
            if (newRow >= 0 && newRow < board.length
                    && newCol >= 0 && newCol < board[0].length
                    && !vis[newRow][newCol]
                    && board[newRow][newCol] != '*') {
                vis[newRow][newCol] = true;
                path++;
                dfs(board, newRow, newCol);
                vis[newRow][newCol] = false;
                path--;
            }
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int m = in.nextInt();
            in.nextLine();
            char[][] board = new char[n][m];
            vis = new boolean[n][m];
            map = new HashMap<>();
            int startX = -1;
            int startY = -1;
            for (int i = 0; i < n; i++) {
                char[] line = in.nextLine().toCharArray();
                for (int j = 0; j < m; j++) {
                    board[i][j] = line[j];
                    if (board[i][j] == 'k') {
                        startX = i;
                        startY = j;
                    }
                }
            }
            Deque<int[]> deque = new LinkedList<>();
            deque.offer(new int[] {startX, startY});
            vis[startX][startY] = true;
            while (deque.size() > 0) {
                int[] arr = deque.poll();
                int row = arr[0];
                int col = arr[1];
                if (board[row][col] == 'e') {
                    minStep = Math.min(minStep, path);
                    Set<Integer> set = map.get(row);
                    if (set == null) {
                        set = new HashSet<>();
                        ret++;
                    } else {
                        if (!set.contains(col)) {
                            ret++;
                        }
                    }
                    set.add(col);
                }
                for (int i = 0; i < 4; i++) {
                    int newRow = row + x[i];
                    int newCol = col + y[i];
                    if (newRow >= 0 && newRow < board.length
                            && newCol >= 0 && newCol < board[0].length
                            && !vis[newRow][newCol]
                            && board[newRow][newCol] != '*') {
                        path++;
                        deque.offer(new int[] {newRow, newCol});
                        vis[newRow][newCol] = true;
                    }
                }
            }
            System.out.println(ret == 0 &&
                    minStep == 0x3f3f3f3f ? -1 : ret + " " + minStep);
        }
    }
}
